package com.wzh.yebServe.controller;

import com.wzh.yebServe.pojo.ResultBean;
import com.wzh.yebServe.pojo.Role;
import com.wzh.yebServe.pojo.User;
import com.wzh.yebServe.service.IUserRoleService;
import com.wzh.yebServe.service.IRoleService;
import com.wzh.yebServe.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/19 13:48
 * @Description:
 */
@Api(tags = "UserController 用户管理接口")
@RestController
@RequestMapping("/system/admin")
public class UserController {
    @Autowired
    private IUserService iUserService;

    @Autowired
    private IRoleService iRoleService;

    @Autowired
    private IUserRoleService iUserRoleService;
    @ApiOperation(value = "获取操作员")
    @GetMapping("/")
    public List<User> getAllUsers(String keywords){
        return iUserService.getAllUsers(keywords);
    }


    @ApiOperation("更新操作员信息")
    @PutMapping("/")
    public ResultBean updateUser(@RequestBody User user){
        return  iUserService.updateUser(user);
    }

    @ApiOperation(value = "删除操作员")
    @DeleteMapping("/{id}")
    public ResultBean deleteUser(@PathVariable Integer id){
        return iUserService.deleteUser(id);
    }


    @ApiOperation(value = "获取所有角色")
    @GetMapping("/roles")
    public List<Role> getAllRoles(){
        return iRoleService.list();
    }

    @ApiOperation(value = "更新操作员角色")
    @PutMapping("/role")
    public ResultBean updateUserRole(Integer userId,Integer [] rids){
      return iUserRoleService.updateUserRole(userId,rids);
    }


}
